﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DoAn_BumTruong_DesignPattern
{
    public class Link
    {
        private static string BuildAbsolute(string relativeUrl)
        {
            Uri uri = HttpContext.Current.Request.Url;
            string app = HttpContext.Current.Request.ApplicationPath;
            if (!app.EndsWith("/"))
                app += "/";
            relativeUrl = relativeUrl.TrimStart('/');
            return HttpUtility.UrlPathEncode(
                String.Format("http://{0}:{1}{2}{3}",
                uri.Host, uri.Port, app, relativeUrl));
        }
        //Module
        public static string ToModule(string page)
        {
            if (page == "1")
            {
                return BuildAbsolute(String.Format("Admin/Module.aspx"));
            }
            else
            {
                return BuildAbsolute(String.Format("/Admin/Module.aspx?Page={0}", page));
            }
        }
        public static string ToModule()
        {
            return ToModule("1");
        }

        //Article
        public static string ToArticle(string page)
        {
            if (page == "1")
            {
                return BuildAbsolute(String.Format("Default.aspx"));
            }
            else
            {
                return BuildAbsolute(String.Format("Default.aspx?Page={0}", page));
            }
        }
        public static string ToArticle()
        {
            return ToArticle("1");
        }
        //MenuID
        public static string ToMenu(string menuID, string page)
        {
            if (page == "1")
            {
                return BuildAbsolute(String.Format("Default.aspx?MenuID={0}", menuID));
            }
            else
            {
                return BuildAbsolute(String.Format("Default.aspx?MenuID={0}&Page={1}", menuID, page));
            }
        }
        public static string ToMenu(string menuID)
        {
            return ToMenu(menuID, "1");
        }
        //
        //Search
        public static string SearchArticle(string title, string page)
        {
            if (page == "1")
            {
                return BuildAbsolute(String.Format("Default.aspx?Title={0}", title));
            }
            else
            {
                return BuildAbsolute(String.Format("Default.aspx?Title={0}&Page={1}", title, page));
            }
        }
        public static string SearchArticle(string title)
        {
            return SearchArticle(title, "1");
        }
        //Paging comment
        public static string ToComment(string page)
        {
            if (page == "1")
            {
                return BuildAbsolute(String.Format("/Admin/Comments.aspx"));
            }
            else
            {
                return BuildAbsolute(String.Format("/Admin/Comments.aspx?Page={0}", page));
            }
        }
        public static string ToComment()
        {
            return ToComment("1");
        }
        //Paging Menu
        public static string ToMenuAdmin(string page)
        {
            if (page == "1")
            {
                return BuildAbsolute(String.Format("/Admin/Menu.aspx"));
            }
            else
            {
                return BuildAbsolute(String.Format("/Admin/Menu.aspx?Page={0}", page));
            }
        }
        public static string ToMenuAdmin()
        {
            return ToMenuAdmin("1");
        }
    }
}